var path = require('path');
var fs = require('fs')

module.exports = (config,webpack) => {
  config.plugins.push(new webpack.optimize.CommonsChunkPlugin({
    name: 'common',
    minChunks: function (module, count) {
      return (
        module.resource &&
        /\.js$/.test(module.resource) &&
        module.resource.indexOf(
          path.join(__dirname, './node_modules')
        ) === 0
      )
    }
  }));

  config.resolve.extensions = ['', '.web.js', '.jsx', '.js', '.json'];
  config.module.loaders = config.module.loaders.filter((n) => !/\.svg/.test(n.test));
  config.module.loaders.forEach((n) => {
    if (/\.jsx/.test(n.test)) {
      n.query.plugins.push(['import', [{ style: 'css', libraryName: 'antd-mobile' }]])
    } else if (/\.css/.test(n.test)) {
      delete n.include;
    }
  });
  config.module.loaders.push({
    test: /.svg$/,
    loader: 'svg-sprite-loader',
  });

  config.output = {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
    publicPath: './'
  };

};
